<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>tango.text.convert.Utf</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "tango.text.convert.Utf";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/tango.text.convert.Utf.html" class="symbol">tango.text.convert.Utf</a></h1>
  
<p class="sec_header">License:</p>BSD style: see <a href="http://www.dsource.org/projects/tango/wiki/LibraryLicense">license.txt</a>
<p class="sec_header">Version:</p>Initial release: Oct 2004
<p class="sec_header">Authors:</p>Kris
<p class="bl"/>
        Fast Unicode transcoders. These are particularly sensitive to
        minor changes on 32bit x86 devices, because the register set of
        those devices is so small. Beware of subtle changes which might
        extend the execution-period by as much as 200%. Because of this,
        three of the six transcoders might read past the end of input by
        one, two, or three bytes before arresting themselves. Note that
        support for streaming adds a 15% overhead to the dchar =&gt; char
        conversion, but has little effect on the others.
<p class="bl"/>
        These routines were tuned on an Intel P4; other devices may work
        more efficiently with a slightly different approach, though this
        is likely to be reasonably optimal on AMD x86 CPUs also. These
        algorithms would benefit significantly from those extra AMD64
        registers. On a 3GHz P4, the dchar/char conversions take around
        2500ns to process an array of 1000 ASCII elements. Invoking the
        memory manager doubles that period, and quadruples the time for
        arrays of 100 elements. Memory allocation can slow down notably
        in a multi-threaded environment, so avoid that where possible.
<p class="bl"/>
        Surrogate-pairs are dealt with in a non-optimal fashion when
        transcoding between utf16 and utf8. Such cases are considered
        to be boundary-conditions for this module.
<p class="bl"/>
        There are three common cases where the input may be incomplete,
        including each 'widening' case of utf8 =&gt; utf16, utf8 =&gt; utf32,
        and utf16 =&gt; utf32. An edge-case is utf16 =&gt; utf8, if surrogate
        pairs are present. Such cases will throw an exception, unless
        streaming-mode is enabled ~ in the latter mode, an additional
        integer is returned indicating how many elements of the input
        have been consumed. In all cases, a correct slice of the output
        is returned.
<p class="bl"/>
        For details on Unicode processing see:
        <ul><a href="http://www.utf-8.com/">http://www.utf-8.com/</a></ul>
        <ul><a href="http://www.hackcraft.net/xmlUnicode/">http://www.hackcraft.net/xmlUnicode/</a></ul>
        <ul><a href="http://www.azillionmonkeys.com/qed/unicode.html/">http://www.azillionmonkeys.com/qed/unicode.html/</a></ul>
        <ul><a href="http://icu.sourceforge.net/docs/papers/forms_of_unicode/">http://icu.sourceforge.net/docs/papers/forms_of_unicode/</a></ul>
<dl>
<dt class="decl">char[] <a class="symbol _function" name="toString" href="./htmlsrc/tango.text.convert.Utf.html#L82" kind="function" beg="82" end="140">toString</a><span class="params">(wchar[] <em>input</em>, char[] <em>output</em> = null, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#toString" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L82">#</a></dt>
<dd class="ddef">
<div class="summary">Encode Utf8 up to a maximum of 4 bytes long (five &amp; six byte
        variations are not supported).</div>
If the output is provided off the stack, it should be large
        enough to encompass the entire transcoding; failing to do
        so will cause the output to be moved onto the heap instead.
<p class="bl"/>
        Returns a slice of the output buffer, corresponding to the
        converted characters. For optimum performance, the returned
        buffer should be specified as 'output' on subsequent calls.
        For example:
<p class="bl"/>
        <pre class="d_code">
<span class="k">char</span>[] <span class="i">output</span>;

<span class="k">char</span>[] <span class="i">result</span> = <span class="i">toString</span> (<span class="i">input</span>, <span class="i">output</span>);

<span class="lc">// reset output after a realloc</span>
<span class="k">if</span> (<span class="i">result</span>.<span class="i">length</span> &gt; <span class="i">output</span>.<span class="i">length</span>)
    <span class="i">output</span> = <span class="i">result</span>;
</pre></dd>
<dt class="decl">wchar[] <a class="symbol _function" name="toString16" href="./htmlsrc/tango.text.convert.Utf.html#L156" kind="function" beg="156" end="221">toString16</a><span class="params">(char[] <em>input</em>, wchar[] <em>output</em> = null, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#toString16" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L156">#</a></dt>
<dd class="ddef">
<div class="summary">Decode Utf8 produced by the above toString() method.</div>
If the output is provided off the stack, it should be large
        enough to encompass the entire transcoding; failing to do
        so will cause the output to be moved onto the heap instead.
<p class="bl"/>
        Returns a slice of the output buffer, corresponding to the
        converted characters. For optimum performance, the returned
        buffer should be specified as 'output' on subsequent calls.</dd>
<dt class="decl">char[] <a class="symbol _function" name="toString:2" href="./htmlsrc/tango.text.convert.Utf.html#L240" kind="function" beg="240" end="306">toString</a><span class="params">(dchar[] <em>input</em>, char[] <em>output</em> = null, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#toString:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L240">#</a></dt>
<dd class="ddef">
<div class="summary">Encode Utf8 up to a maximum of 4 bytes long (five &amp; six
        byte variations are not supported). Throws an exception
        where the input dchar is greater than 0x10ffff.</div>
If the output is provided off the stack, it should be large
        enough to encompass the entire transcoding; failing to do
        so will cause the output to be moved onto the heap instead.
<p class="bl"/>
        Returns a slice of the output buffer, corresponding to the
        converted characters. For optimum performance, the returned
        buffer should be specified as 'output' on subsequent calls.</dd>
<dt class="decl">dchar[] <a class="symbol _function" name="toString32" href="./htmlsrc/tango.text.convert.Utf.html#L323" kind="function" beg="323" end="396">toString32</a><span class="params">(char[] <em>input</em>, dchar[] <em>output</em> = null, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#toString32" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L323">#</a></dt>
<dd class="ddef">
<div class="summary">Decode Utf8 produced by the above toString() method.</div>
If the output is provided off the stack, it should be large
        enough to encompass the entire transcoding; failing to do
        so will cause the output to be moved onto the heap instead.
<p class="bl"/>
        Returns a slice of the output buffer, corresponding to the
        converted characters. For optimum performance, the returned
        buffer should be specified as 'output' on subsequent calls.</dd>
<dt class="decl">wchar[] <a class="symbol _function" name="toString16:2" href="./htmlsrc/tango.text.convert.Utf.html#L413" kind="function" beg="413" end="461">toString16</a><span class="params">(dchar[] <em>input</em>, wchar[] <em>output</em> = null, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#toString16:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L413">#</a></dt>
<dd class="ddef">
<div class="summary">Encode Utf16 up to a maximum of 2 bytes long. Throws an exception
        where the input dchar is greater than 0x10ffff.</div>
If the output is provided off the stack, it should be large
        enough to encompass the entire transcoding; failing to do
        so will cause the output to be moved onto the heap instead.
<p class="bl"/>
        Returns a slice of the output buffer, corresponding to the
        converted characters. For optimum performance, the returned
        buffer should be specified as 'output' on subsequent calls.</dd>
<dt class="decl">dchar[] <a class="symbol _function" name="toString32:2" href="./htmlsrc/tango.text.convert.Utf.html#L477" kind="function" beg="477" end="530">toString32</a><span class="params">(wchar[] <em>input</em>, dchar[] <em>output</em> = null, uint* <em>ate</em> = null)</span>; <a title="Permalink to this symbol" href="#toString32:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L477">#</a></dt>
<dd class="ddef">
<div class="summary">Decode Utf16 produced by the above toString16() method.</div>
If the output is provided off the stack, it should be large
        enough to encompass the entire transcoding; failing to do
        so will cause the output to be moved onto the heap instead.
<p class="bl"/>
        Returns a slice of the output buffer, corresponding to the
        converted characters. For optimum performance, the returned
        buffer should be specified as 'output' on subsequent calls.</dd>
<dt class="decl">dchar <a class="symbol _function" name="decode" href="./htmlsrc/tango.text.convert.Utf.html#L540" kind="function" beg="540" end="544">decode</a><span class="params">(char[] <em>src</em>, inout uint <em>ate</em>)</span>; <a title="Permalink to this symbol" href="#decode" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L540">#</a></dt>
<dd class="ddef">
<div class="summary">Decodes a single dchar from the given src text, and indicates how
        many chars were consumed from src to do so.</div></dd>
<dt class="decl">dchar <a class="symbol _function" name="decode:2" href="./htmlsrc/tango.text.convert.Utf.html#L553" kind="function" beg="553" end="557">decode</a><span class="params">(wchar[] <em>src</em>, inout uint <em>ate</em>)</span>; <a title="Permalink to this symbol" href="#decode:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L553">#</a></dt>
<dd class="ddef">
<div class="summary">Decodes a single dchar from the given src text, and indicates how
        many wchars were consumed from src to do so.</div></dd>
<dt class="decl">char[] <a class="symbol _function" name="encode" href="./htmlsrc/tango.text.convert.Utf.html#L566" kind="function" beg="566" end="569">encode</a><span class="params">(char[] <em>dst</em>, dchar <em>c</em>)</span>; <a title="Permalink to this symbol" href="#encode" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L566">#</a></dt>
<dd class="ddef">
<div class="summary">Encode a dchar into the provided dst array, and return a slice of 
        it representing the encoding</div></dd>
<dt class="decl">wchar[] <a class="symbol _function" name="encode:2" href="./htmlsrc/tango.text.convert.Utf.html#L578" kind="function" beg="578" end="581">encode</a><span class="params">(wchar[] <em>dst</em>, dchar <em>c</em>)</span>; <a title="Permalink to this symbol" href="#encode:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L578">#</a></dt>
<dd class="ddef">
<div class="summary">Encode a dchar into the provided dst array, and return a slice of 
        it representing the encoding</div></dd>
<dt class="decl">bool <a class="symbol _function" name="isValid" href="./htmlsrc/tango.text.convert.Utf.html#L589" kind="function" beg="589" end="592">isValid</a><span class="params">(dchar <em>c</em>)</span>; <a title="Permalink to this symbol" href="#isValid" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L589">#</a></dt>
<dd class="ddef">
<div class="summary">Is the given character valid?</div></dd>
<dt class="decl">T[] <a class="symbol _function" name="fromString8" href="./htmlsrc/tango.text.convert.Utf.html#L604" kind="function" beg="604" end="614">fromString8</a><span class="tparams">(T)</span><span class="params">(char[] <em>s</em>, T[] <em>dst</em>)</span>; <a title="Permalink to this symbol" href="#fromString8" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L604">#</a></dt>
<dd class="ddef">
<div class="summary">Convert from a char[] into the type of the dst provided.</div>
Returns a slice of the given dst, where it is sufficiently large
        to house the result, or a heap-allocated array otherwise. Returns
        the original input where no conversion is required.</dd>
<dt class="decl">T[] <a class="symbol _function" name="fromString16" href="./htmlsrc/tango.text.convert.Utf.html#L626" kind="function" beg="626" end="636">fromString16</a><span class="tparams">(T)</span><span class="params">(wchar[] <em>s</em>, T[] <em>dst</em>)</span>; <a title="Permalink to this symbol" href="#fromString16" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L626">#</a></dt>
<dd class="ddef">
<div class="summary">Convert from a wchar[] into the type of the dst provided.</div>
Returns a slice of the given dst, where it is sufficiently large
        to house the result, or a heap-allocated array otherwise. Returns
        the original input where no conversion is required.</dd>
<dt class="decl">T[] <a class="symbol _function" name="fromString32" href="./htmlsrc/tango.text.convert.Utf.html#L648" kind="function" beg="648" end="658">fromString32</a><span class="tparams">(T)</span><span class="params">(dchar[] <em>s</em>, T[] <em>dst</em>)</span>; <a title="Permalink to this symbol" href="#fromString32" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L648">#</a></dt>
<dd class="ddef">
<div class="summary">Convert from a dchar[] into the type of the dst provided.</div>
Returns a slice of the given dst, where it is sufficiently large
        to house the result, or a heap-allocated array otherwise. Returns
        the original input where no conversion is required.</dd>
<dt class="decl">T[] <a class="symbol _function" name="cropLeft" href="./htmlsrc/tango.text.convert.Utf.html#L669" kind="function" beg="669" end="682">cropLeft</a><span class="tparams">(T)</span><span class="params">(T[] <em>s</em>)</span>; <a title="Permalink to this symbol" href="#cropLeft" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L669">#</a></dt>
<dd class="ddef">
<div class="summary">Adjust the content such that no partial encodings exist on the 
        left side of the provided text.</div>
Returns a slice of the input</dd>
<dt class="decl">T[] <a class="symbol _function" name="cropRight" href="./htmlsrc/tango.text.convert.Utf.html#L693" kind="function" beg="693" end="725">cropRight</a><span class="tparams">(T)</span><span class="params">(T[] <em>s</em>)</span>; <a title="Permalink to this symbol" href="#cropRight" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.text.convert.Utf.html#L693">#</a></dt>
<dd class="ddef">
<div class="summary">Adjust the content such that no partial encodings exist on the 
        right side of the provided text.</div>
Returns a slice of the input</dd></dl>
</div>
<div id="footer">
  <p>Copyright (c) 2004 Kris Bell. All rights reserved</p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Fri Dec 26 04:04:47 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>